package com.macro.mall.wx.service.impl;

import com.macro.mall.common.util.HttpClient;
import com.macro.mall.wx.API.WxAPI;
import com.macro.mall.wx.service.GetQrCodeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Service
public class GetQrCodeServiceImpl implements GetQrCodeService {
    @Override
    public byte[] getQrCode(String scene, String page,String accessToken) {
        byte[] qrCodeBytes = null;
        Map<String, String> paraMap = new HashMap();
        if(StringUtils.isNotBlank(scene)){
            paraMap.put("scene", scene);  //存入的参数
        }
        if(StringUtils.isNotBlank(page)){
            paraMap.put("page", page);  //存入的参数
        }
        String url= WxAPI.GET_QR_CODE+"access_token="+accessToken;
        try {
            qrCodeBytes = HttpClient.post(url, paraMap);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //二维码携带参数 不超过32位 参数类型必须是字符串
        return qrCodeBytes;
    }
}
